package com.xinbo.tuiyousuper.fragment;

import java.util.ArrayList;
import java.util.List;

import com.xinbo.tuiyousuper.R;
import com.xinbo.tuiyousuper.model.UserData;
import com.xinbo.tuiyousuper.utils.Constans;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

/**
 * A simple {@link Fragment} subclass.
 *
 */
public class BlankFragment4 extends Fragment
{
	private LayoutInflater inflater;
	private boolean isHide;
	private List<UserData> list = new ArrayList<UserData>();
	private List<UserData> list2 = new ArrayList<UserData>();
	private int[] images =
	{ R.drawable.bf4_01, R.drawable.bf4_02, R.drawable.bf4_03,
	        R.drawable.bf4_04, R.drawable.bf4_05, R.drawable.bf4_06,
	        R.drawable.bf4_07, R.drawable.bf4_08, R.drawable.bf4_09, };
	private int[] images2 =
	{ R.drawable.mudidi01, R.drawable.mudidi02, R.drawable.mudidi03,
	        R.drawable.mudidi04, R.drawable.mudidi05, R.drawable.mudidi06,
	        R.drawable.mudidi07, R.drawable.mudidi08, R.drawable.mudidi09,
	        R.drawable.mudidi10, R.drawable.mudidi11, R.drawable.mudidi12,
	        R.drawable.mudidi13 };
	private MyAdapter2 adapter2;

	public BlankFragment4()
	{
		// Required empty public constructor
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
	        Bundle savedInstanceState)
	{
		this.inflater = inflater;
		View layout = inflater.inflate(R.layout.fragment_blank_fragment4,
		        container, false);
		ListView mListView1 = (ListView) layout
		        .findViewById(R.id.listView1_bf4);
		ListView mListView2 = (ListView) layout
		        .findViewById(R.id.listView2_bf4);
		mListView1.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
		list.clear();
		
		for (int i = 0; i < Constans.Text.MUDIDI_TITLE.length; i++)
		{
			String title = Constans.Text.MUDIDI_TITLE[i];
			int image = images[i];
			list.add(new UserData(title, "", image));
		}
		initData();
		MyAdapter adapter = new MyAdapter();
		adapter2 = new MyAdapter2();
		mListView1.setAdapter(adapter);
		mListView2.setAdapter(adapter2);
		mListView1.performItemClick(mListView1, 0, 0);
		mListView1.setOnItemClickListener(new OnItemClickListener()
		{

			@Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id)
            {
	            if (position==0)
                {
	                isHide=false;
	                initData();
                }else if(position==1){
                	 isHide=true;
                	 initData2();
				}else if(position==2){
               	 isHide=true;
               	 initData3();
				}else if(position==3){
               	 isHide=true;
               	 initData4();
				}else if(position==4){
               	 isHide=true;
               	 initData5();
				}else if(position==5){
               	 isHide=true;
               	 initData6();
				}else if(position==6){
               	 isHide=true;
               	 initData7();
				}else if(position==7){
               	 isHide=true;
               	 initData8();
				}else if(position==8){
               	 isHide=true;
               	 initData9();
				}
	            adapter2.notifyDataSetChanged();
            }
		});
		return layout;
	}

	private void initData2()
    {
		list2.clear();
	    for (int i = 0; i < Constans.DataCache.MUDIDI_ZHOUBIAN.length; i++)
        {
			String title = Constans.DataCache.MUDIDI_ZHOUBIAN[i];
			String name = Constans.DataCache.MUDIDI_ZHOUBIAN2[i];
			list2.add(new UserData(title, name,0));
        }
    }
	private void initData3()
	{
		list2.clear();
		for (int i = 0; i < Constans.DataCache.MUDIDI_GUOENI.length; i++)
		{
			String title = Constans.DataCache.MUDIDI_GUOENI[i];
			String name = Constans.DataCache.MUDIDI_GUOENI2[i];
			list2.add(new UserData(title, name,0));
		}
	}
	private void initData4()
	{
		list2.clear();
		for (int i = 0; i < Constans.DataCache.MUDIDI_MAERDAIFU.length; i++)
		{
			String title = Constans.DataCache.MUDIDI_MAERDAIFU[i];
			list2.add(new UserData(title, "",0));
		}
	}
	private void initData5()
	{
		list2.clear();
		for (int i = 0; i < Constans.DataCache.MUDIDI_OUZHOUMEIZHOU.length; i++)
		{
			String title = Constans.DataCache.MUDIDI_OUZHOUMEIZHOU[i];
			String name = Constans.DataCache.MUDIDI_OUZHOUMEIZHOU2[i];
			list2.add(new UserData(title, name,0));
		}
	}
	private void initData6()
	{
		list2.clear();
		for (int i = 0; i < Constans.DataCache.MUDIDI_RIHAN.length; i++)
		{
			String title = Constans.DataCache.MUDIDI_RIHAN[i];
			String name = Constans.DataCache.MUDIDI_RIHAN2[i];
			list2.add(new UserData(title, name,0));
		}
	}
	private void initData7()
	{
		list2.clear();
		for (int i = 0; i < Constans.DataCache.MUDIDI_DONGNANYA.length; i++)
		{
			String title = Constans.DataCache.MUDIDI_DONGNANYA[i];
			String name = Constans.DataCache.MUDIDI_DONGNANYA2[i];
			list2.add(new UserData(title, name,0));
		}
	}
	private void initData8()
	{
		list2.clear();
		for (int i = 0; i < Constans.DataCache.MUDIDI_GANGAOTAI.length; i++)
		{
			String title = Constans.DataCache.MUDIDI_GANGAOTAI[i];
			String name = Constans.DataCache.MUDIDI_GANGAOTAI2[i];
			list2.add(new UserData(title, name,0));
		}
	}
	private void initData9()
	{
		list2.clear();
		for (int i = 0; i < Constans.DataCache.MUDIDI_AOZHOUZHONGDONGFEI.length; i++)
		{
			String title = Constans.DataCache.MUDIDI_AOZHOUZHONGDONGFEI[i];
			String name = Constans.DataCache.MUDIDI_AOZHOUZHONGDONGFEI2[i];
			list2.add(new UserData(title, name,0));
		}
	}
	private void initData()
    {
		list2.clear();
	    for (int i = 0; i < images2.length; i++)
		{
			String title = Constans.Text.MUDIDI_TITLE2[i];
			int image = images2[i];
			list2.add(new UserData(title, "", image));
		}
    }

	class MyAdapter extends BaseAdapter
	{

		@Override
		public int getCount()
		{

			return list.size();
		}

		@Override
		public Object getItem(int position)
		{
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getItemId(int position)
		{
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent)
		{
			View layout = inflater.inflate(R.layout.bf4_listview1_item, null);
			ImageView mImageView = (ImageView) layout
			        .findViewById(R.id.imageView1_bf4);
			TextView mTextView = (TextView) layout
			        .findViewById(R.id.textView1_bf4);
			UserData userData = list.get(position);
			mImageView.setImageResource(userData.getImage());
			mTextView.setText(userData.getTitle());
			return layout;
		}

	}

	class MyAdapter2 extends BaseAdapter
	{

		@Override
		public int getCount()
		{

			return list2.size();
		}

		@Override
		public Object getItem(int position)
		{
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getItemId(int position)
		{
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent)
		{
			View layout = inflater.inflate(R.layout.bf4_listview2_item, null);
			ImageView mImageView = (ImageView) layout
			        .findViewById(R.id.imageView2_bf4);
			TextView mTextView = (TextView) layout
			        .findViewById(R.id.textView2_bf4);
			View hide = layout.findViewById(R.id.RelativeLayout1_bf4);
			View show = layout.findViewById(R.id.FrameLayout2_bf4);
			TextView tvTitle = (TextView) layout.findViewById(R.id.tv_title_2_bf2);
			TextView tvContent = (TextView) layout.findViewById(R.id.tv_content_2_bf2);
			UserData userData = list2.get(position);
			if (!isHide)
            {
				hide.setVisibility(View.GONE);
				show.setVisibility(View.VISIBLE);
				mImageView.setImageResource(userData.getImage());
				mTextView.setText(userData.getTitle());
            }else {
				hide.setVisibility(View.VISIBLE);
				show.setVisibility(View.GONE);
				tvTitle.setText(userData.getTitle());
				if (!"".equals(userData.getName()))
                {
					tvContent.setVisibility(View.VISIBLE);
					tvContent.setText(userData.getName());
                }else {
                	tvContent.setVisibility(View.GONE);
				}
			}
			return layout;
		}

	}
}
